class WelcomeController < ApplicationController

  def index
    @auth = Person.auth.from_signed_request(params[:signed_request]) if request.post? && params[:signed_request]
    
    if @auth && @auth.authorized?
      session[:person_id] = Person.identify(@auth.user).id
    end
    
    redirect
  end
  
  def canvas
    redirect_to SiteConfig.canvas_url + "&app_data=#{params[:app_data]}"
  end
  
  
  protected
  
    def redirect
      if @auth && @auth.authorized? && @auth.data["app_data"]
        url = [""]
        url << @auth.data["app_data"]
        
        redirect_to url.join('/')
      end
    end
end
